Conversation
…ad of null Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix clipboard code examples to handle NotSupportedException
Fix clipboard GetData documentation to reflect NotSupportedException instead of null
Nov 12, 2025
adegeo
approved these changes
Nov 12, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes documentation comments in code examples that incorrectly stated Clipboard.GetData() returns null when BinaryFormatter is unavailable. The actual behavior is that it returns a NotSupportedException instance.
- Updated 4 comment lines across C# and VB code example files
- Changes align with the main article documentation which correctly describes the exception return behavior
- All modifications are limited to comments only; no code logic was changed
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet-desktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/csharp/ObsoletePatterns.cs | Updated 2 comments to reflect that GetData() returns a NotSupportedException instance instead of null |
| dotnet-desktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/vb/ObsoletePatterns.vb | Updated 2 comments to reflect that GetData() returns a NotSupportedException instance instead of null |
adegeo
reviewed
Nov 17, 2025
...-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/csharp/ObsoletePatterns.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
adegeo
reviewed
Nov 18, 2025
...ktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/vb/ObsoletePatterns.vb
Outdated
Show resolved
Hide resolved
adegeo
approved these changes
Nov 18, 2025
Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
adegeo
approved these changes
Nov 18, 2025
Contributor
|
@BillWagner This is ready |
IEvangelist
approved these changes
Nov 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Code examples incorrectly documented that
Clipboard.GetData()returnsnullwhenBinaryFormatteris unavailable. The actual behavior returns aNotSupportedExceptioninstance. Additionally, the code examples were checking for null instead of validating the returned type.Changes
ObsoletePatterns.cs/vbto accurately reflect exception behaviorif (data != null)toif (data is Person person)using pattern matchingIf data IsNot Nothing ThentoIf TypeOf data Is Person ThenCTypetoDirectCastfor better performance after type validationExample
VB Example
This aligns the code examples with the main article documentation, which correctly states that
GetData()returns aNotSupportedExceptionwhenBinaryFormatteris required but not enabled, and ensures the code properly validates the type before using the data.Fixes #2146
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.